package com.itheima.es.handler;

import com.itheima.common.exception.BusinessException;
import com.itheima.common.response.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理
 *
 * @author liqp
 * @version 1.0
 * @date 2021/1/28
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public ResponseResult handleExcepting(BusinessException e) {
        return new ResponseResult(1510, e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseResult handleExcepting(Exception e) {
        log.error("error", e);
        return new ResponseResult(1500, e.getMessage());
    }
}
